﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using LightPersist.Metainfo;

namespace LightPersist
{
	/// <summary>
	/// Используется в гетерогенных списках объектов, которые могут быть
	/// как моделью, так и примитивами
	/// </summary>
	internal class ValueModelWrapper : ModelBase
	{
		static ValueModelWrapper()
		{
			LightPersistContext.RegisterFactory<ValueModelWrapper>(ctx => new ValueModelWrapper(ctx));
			Metainfo.PropertiesDeclared.Add(new PropertyMetainfo
			                        	{
			                        		IsReadonly = false,
			                        		Name = "Value",
			                        		Type = typeof (object).FullName,
			                        		TypeClrPersist = typeof (object),
			                        		UntypedBehaviour = UntypedPropertyBehaviour.PrimitiveOnly,
			                        	});
		}

		new internal readonly static ClassMetainfo Metainfo = new ClassMetainfo
		{
			Name = DomainMetainfo.ValueModelWrapperAqn,
			TypeClrPersist = typeof(ValueModelWrapper),
		};

		const string _valuePropertyName = "Value";

		public ValueModelWrapper(LightPersistContext ctx) : base(ctx)
		{
		}

		public object Value
		{
			get
			{
				return GetValue<object>(_valuePropertyName);
			}
			internal set
			{
				SetValue<object>(value, _valuePropertyName);
			}
		}

		public override bool Equals(object obj)
		{
			throw new NotImplementedException();
		}

		public override int GetHashCode()
		{
			throw new NotImplementedException();
		}
	}
}
